library(survey)
library(dplyr)
library(stargazer)
library(performance)

## creating Model for Table 3.9
# model: multivariate model based on demographics, logit specification, DV: Q11_d

summary(factor(df$Q11))
summary(factor(df$Q11_d))
summary(factor(df$Q33))

# Recode attention to military news
df$Q33[df$Q33 == 1] <- 7
df$Q33[df$Q33 == 2] <- 6
df$Q33[df$Q33 == 3] <- 5
df$Q33 <- df$Q33 - 3
summary(factor(df$Q33))

## Create weighted survey design object
w2_design <-
  svydesign(
    id = ~ 1,
    weights = ~ weight2,
    data = df[df$Q33<5,]
  )

summary(factor(w2_design$variables$Q33))

## creating Model for Table 3.9
# model: multivariate model based on demographics, logit specification, DV: Q11_d
fig3.9_mod <- svyglm(Q11_d ~ Q33 + dem + rep + ideo3 + 
                       male + white + black + hispanic + asian + 
                       income5 + EDUC5 + unemployed + married + 
                       silent + boomer + genx + millen + 
                       activeduty + vet + social + family + 
                       midwest + south + west + 
                       catholic + christian + norelig +
                       city + rural + 
                       A2 + A3 + A4 + A5 + A6 + A7 + A8,
                     family = binomial(link = "logit"),
                     design = w2_design)

summary(fig3.9_mod)
check_collinearity(fig3.9_mod)
stargazer(fig3.9_mod)

